
let db = require('../utils/DB');//数据库
let to = require('../utils/await-to-js');
let { SUCCESS1, ERROR } = require('../utils/result');//结果
let jwt = require('../utils/jwt');

//更新购物车商品
function updateModel() {
    return async (req, res) => {
        
        let { id,num, token } = req.query;//购物车商品id  数量 token
        let { uid } = jwt.base64ToJson(token.split('.')[1]);//用户id

        let [err, data] = await to(db.query(`UPDATE  shopcar SET goods_num=? WHERE  id=? AND uid=?`, [num,id, uid]));
        err ? ERROR(res, '修改购物车失败', err) : SUCCESS1(res, '修改购物商品成功');
    };
}


module.exports = updateModel;